//
//  CommentCell.m
//  HomeIn
//
//  Created by dllo on 15/11/7.
//  Copyright © 2015年 ZZP. All rights reserved.
//

#import "CommentCell.h"
#import "CommentModel.h"

@implementation CommentCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews
{
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    //头像
    self.ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, self.contentView.frame.size.width / 4, HEIGHT / 6 - 20)];
    [self.contentView addSubview:self.ImageView];
    
    //名字
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.ImageView.frame.origin.x + self.ImageView.frame.size.width + 10, self.ImageView.frame.origin.y, self.contentView.frame.size.width / 2, self.contentView.frame.size.height / 3)];
    [self.contentView addSubview:self.nameLabel];
    
    //内容
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nameLabel.frame.origin.x , self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height, self.contentView.frame.size.width - self.ImageView.frame.origin.x - self.ImageView.frame.size.width - 10 - 10, HEIGHT / 6 / 3 * 2)];
    [self.contentView addSubview:self.contentLabel];
    
    
}

- (void)setCommentModel:(CommentModel *)commentModel
{
    _commentModel = commentModel;

    //取出大字典中的小字典
    CommentModel *comment = [[CommentModel alloc] init];
    NSMutableDictionary *dic = _commentModel.user;
    [comment setValuesForKeysWithDictionary:dic];
    
    [self.ImageView sd_setImageWithURL:[NSURL URLWithString:comment.avatar_url]];
    
    self.nameLabel.text = comment.nickname;
    self.nameLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
    
    self.contentLabel.text = _commentModel.content;
    self.contentLabel.textColor = [UIColor grayColor];
    self.contentLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
    self.contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.contentLabel.numberOfLines = 0;

    
}

@end
